package concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * @author zhangxin
 * @date 2020/12/3
 */
public class CountDownLatchTest {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(2);
        new Thread(() -> {
            countDownLatch.countDown();
            System.out.println("t1等待结束，开始新任务");
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();


        new Thread(() -> {

            try {
                Thread.sleep(3300);
                countDownLatch.countDown();

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("t2等待结束，开始新任务");
        }).start();


        countDownLatch.await();


        System.out.println("main end");
    }
}
